﻿using System;
using System.IO;

namespace Nb.Common.Logs
{
    public class LoggerManager
    {
        static ILoggerProvider _loggerProvider;
        public static void SetLoggerManager(ILoggerProvider loggerProvider)
        {
            if (loggerProvider == null)
            {
                throw new ArgumentNullException();
            }
            _loggerProvider = loggerProvider;
        }

        public static ILogger GetTheLogger<T>()
        {
            CheckInit();
            var log = _loggerProvider.GetLogger<T>();
            return log;
        }
        public static ILogger GetTheLogger(Type type)
        {
            CheckInit();
            var log = _loggerProvider.GetLogger(type);
            return log;
        }
        public static ILogger GetTheLogger(string name)
        {
            CheckInit();
            return _loggerProvider.GetLogger(name);
        }
        public static ILogger GetTheLogger()
        {
            CheckInit();
            return _loggerProvider.GetLogger();
        }

        private static void CheckInit()
        {
            if (_loggerProvider == null)
            {
                throw new Exception("LoggerManager在使用前，必须用ILoggerProvider先进行初始化！");
            }
        }
    }
}